package com.hjj.AppIO;

import java.io.*;

public class MyApp9 {
    public static void main(String[] args) {
        String pathSrc = "F:\\IO\\aa.txt";

        String pathDsc = "F:\\IO\\bb.txt";

        int byteSize = 10;

        File fileDsc = new File(pathDsc);
        if (fileDsc.exists()){
            boolean delete = fileDsc.delete();
            if (!delete){
                System.out.println("文件删除失败");
                return;
            }
        }

        try {
            boolean mkdir = fileDsc.createNewFile();

            if (!mkdir){
                System.out.println("文件创建失败");
                return;
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件创建失败.....IO异常");
        }

        byte[] bytes = new byte[byteSize];

        try {
            FileInputStream fileInputStream = new FileInputStream(pathSrc);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream, 10);

            FileOutputStream fileOutputStream = new FileOutputStream(pathDsc);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream, 10);

            int js = 0;
            int read = 0;

            while ((read = bufferedInputStream.read(bytes, 0, bytes.length)) != -1) {
                js += read;
                System.out.println("开始写入..........." + js);
                bufferedOutputStream.write(bytes, 0, read);
            }


            bufferedInputStream.close();
            bufferedOutputStream.close();
            fileInputStream.close();
            fileOutputStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
